package com.paranoidmonkey.ode;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import android.util.Log;

public class AndrODE {

	static{
		Log.d("AndrODE", "Loading dll");
		System.loadLibrary("AndrODE");
		Log.d("AndrODE", "Load ok");
		
		dInitODE();
	}

	// ---------------------- geom
	
	public final static native void dGeomDestroy(long GeomID);

	public final static native void dGeomSetData(long GeomID, Object data);

	public final static native Object dGeomGetData(long GeomID);

	public final static native void dGeomSetBody(long GeomID, long body);

	public final static native long dGeomGetBody(long GeomID);

	public final static native void dGeomSetPosition(long GeomID, float x,
			float y, float z);

	public final static native void dGeomSetRotation(long GeomID, float[] R);

	public final static native void dGeomSetQuaternion(long GeomID, float[] Q);

	public final static native float[] dGeomGetPosition(long GeomID);

	public final static native void dGeomCopyPosition(long GeomID, float[] pos);

	public final static native float[] dGeomGetRotation(long GeomID);

	public final static native void dGeomCopyRotation(long GeomID, float[] R);

	public final static native void dGeomGetQuaternion(long GeomID,
			float[] result);

	public final static native void dGeomGetAABB(long GeomID, float[] aabb);

	public final static native int dGeomIsSpace(long GeomID);

	public final static native long dGeomGetSpace(long GeomID);

	public final static native int dGeomGetClass(long GeomID);

	public final static native void dGeomSetCategoryBits(long GeomID, long bits);

	public final static native void dGeomSetCollideBits(long GeomID, long bits);

	public final static native long dGeomGetCategoryBits(long GeomID);

	public final static native long dGeomGetCollideBits(long GeomID);

	public final static native void dGeomEnable(long GeomID);

	public final static native void dGeomDisable(long GeomID);

	public final static native int dGeomIsEnabled(long GeomID);

	public final static native int dGeomLowLevelControl(long GeomID,
			int controlClass, int controlCode, Buffer dataValue, int[] dataSize);

	public final static native void dGeomGetRelPointPos(long GeomID, float px,
			float py, float pz, float[] result);

	public final static native void dGeomGetPosRelPoint(long GeomID, float px,
			float py, float pz, float[] result);

	public final static native void dGeomVectorToWorld(long GeomID, float px,
			float py, float pz, float[] result);

	public final static native void dGeomVectorFromWorld(long GeomID, float px,
			float py, float pz, float[] result);

	public final static native void dGeomSetOffsetPosition(long GeomID,
			float x, float y, float z);

	public final static native void dGeomSetOffsetRotation(long GeomID,
			float[] R);

	public final static native void dGeomSetOffsetQuaternion(long GeomID,
			float[] Q);

	public final static native void dGeomSetOffsetWorldPosition(long GeomID,
			float x, float y, float z);

	public final static native void dGeomSetOffsetWorldRotation(long GeomID,
			float[] R);

	public final static native void dGeomSetOffsetWorldQuaternion(long GeomID,
			float[] quaternion);

	public final static native void dGeomClearOffset(long GeomID);

	public final static native int dGeomIsOffset(long GeomID);

	public final static native float[] dGeomGetOffsetPosition(long GeomID);

	public final static native void dGeomCopyOffsetPosition(long GeomID,
			float[] pos);

	public final static native float[] dGeomGetOffsetRotation(long GeomID);

	public final static native void dGeomCopyOffsetRotation(long GeomID,
			float[] R);

	public final static native void dGeomGetOffsetQuaternion(long GeomID,
			float[] result);

	public final static native long dCreateSphere(long space, float radius);

	public final static native void dGeomSphereSetRadius(long sphere,
			float radius);

	public final static native float dGeomSphereGetRadius(long sphere);

	public final static native float dGeomSpherePointDepth(long sphere,
			float x, float y, float z);

	public final static native long dCreateConvex(long space, float[] _planes,
			int _planecount, float[] _points, int _pointcount, int[] _polygons);

	public final static native void dGeomSetConvex(long g, float[] _planes,
			int _count, float[] _points, int _pointcount, int[] _polygons);

	public final static native long dCreateBox(long space, float lx, float ly,
			float lz);

	public final static native void dGeomBoxSetLengths(long box, float lx,
			float ly, float lz);

	public final static native void dGeomBoxGetLengths(long box, float[] result);

	public final static native float dGeomBoxPointDepth(long box, float x,
			float y, float z);

	public final static native long dCreatePlane(long space, float a, float b,
			float c, float d);

	public final static native void dGeomPlaneSetParams(long plane, float a,
			float b, float c, float d);

	public final static native void dGeomPlaneGetParams(long plane,
			float[] result);

	public final static native float dGeomPlanePointDepth(long plane, float x,
			float y, float z);

	public final static native long dCreateCapsule(long space, float radius,
			float length);

	public final static native void dGeomCapsuleSetParams(long ccylinder,
			float radius, float length);

	public final static native void dGeomCapsuleGetParams(long ccylinder,
			float[] radius, float[] length);

	public final static native float dGeomCapsulePointDepth(long ccylinder,
			float x, float y, float z);

	public final static native long dCreateCylinder(long space, float radius,
			float length);

	public final static native void dGeomCylinderSetParams(long cylinder,
			float radius, float length);

	public final static native void dGeomCylinderGetParams(long cylinder,
			float[] radius, float[] length);

	public final static native long dCreateRay(long space, float length);

	public final static native void dGeomRaySetLength(long ray, float length);

	public final static native float dGeomRayGetLength(long ray);

	public final static native void dGeomRaySet(long ray, float px, float py,
			float pz, float dx, float dy, float dz);

	public final static native void dGeomRayGet(long ray, float[] start,
			float[] dir);

	public final static native void dGeomRaySetParams(long g, int FirstContact,
			int BackfaceCull);

	public final static native void dGeomRayGetParams(long g,
			int[] FirstContact, int[] BackfaceCull);

	public final static native void dGeomRaySetClosestHit(long g, int closestHit);

	public final static native int dGeomRayGetClosestHit(long g);

	public final static native long dCreateGeomTransform(long space);

	public final static native void dGeomTransformSetGeom(long g, long GeomID);

	public final static native long dGeomTransformGetGeom(long g);

	public final static native void dGeomTransformSetCleanup(long g, int mode);

	public final static native int dGeomTransformGetCleanup(long g);

	public final static native void dGeomTransformSetInfo(long g, int mode);

	public final static native int dGeomTransformGetInfo(long g);

	// ----------------- Heightfield
	public final static native long dCreateHeightfield(long space, long data,
			int bPlaceable);

	public final static native long dGeomHeightfieldDataCreate();

	public final static native void dGeomHeightfieldDataDestroy(long d);

	// public final static native void dGeomHeightfieldDataBuildCallback( long
	// d,
	// Buffer pUserData, dHeightfieldGetHeight[] pCallback,
	// float width, float depth, int widthSamples, int depthSamples,
	// float scale, float offset, float thickness, int bWrap );

	// these 4 assume bCopyHeightData as true
	public final static native void dGeomHeightfieldDataBuildByte(long d, byte[] pHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset,float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildShort(long d, short[] pHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildSingle(long d, float[] pHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildDouble(long d, double[] pHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);

	// these 4 don't
	public final static native void dGeomHeightfieldDataBuildByte(long d, ByteBuffer pHeightData, int bCopyHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset,float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildShort(long d, ShortBuffer pHeightData, int bCopyHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildSingle(long d, FloatBuffer pHeightData, int bCopyHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);
	public final static native void dGeomHeightfieldDataBuildDouble(long d, DoubleBuffer pHeightData, int bCopyHeightData, float width, float depth, int widthSamples, int depthSamples, float scale, float offset, float thickness, int bWrap);

	public final static native void dGeomHeightfieldDataSetBounds(long d,
			float minHeight, float maxHeight);

	public final static native void dGeomHeightfieldSetHeightfieldData(
			long GeomID, long d);

	public final static native long dGeomHeightfieldGetHeightfieldData(
			long GeomID);

	public final static native void dClosestLineSegmentPoints(float[] a1,
			float[] a2, float[] b1, float[] b2, float[] cp1, float[] cp2);

	public final static native int dBoxTouchesBox(float[] _p1, float[] R1,
			float[] side1, float[] _p2, float[] R2, float[] side2);

	public final static native int dBoxBox(float[] p1, float[] R1,
			float[] side1, float[] p2, float[] R2, float[] side2,
			float[] normal, float[] depth, int[] return_code, int flags,
			long contact, int skip);

	public final static native void dInfiniteAABB(long GeomID, float[] aabb);

	public final static native int dCreateGeomClass(long classptr);

	public final static native Buffer dGeomGetClassData(long GeomID);

	public final static native long dCreateGeom(int classnum);

	// ---------------------- space

	public final static native long dSimpleSpaceCreate(long space);

	public final static native long dHashSpaceCreate(long space);

	public final static native long dQuadTreeSpaceCreate(long space,
			float[] Center, float[] Extents, int Depth);

	public final static native long dSweepAndPruneSpaceCreate(long space,
			int axisorder);

	public final static native void dSpaceDestroy(long space);

	public final static native void dHashSpaceSetLevels(long space,
			int minlevel, int maxlevel);

	public final static native void dHashSpaceGetLevels(long space,
			int[] minlevel, int[] maxlevel);

	public final static native void dSpaceSetCleanup(long space, int mode);

	public final static native int dSpaceGetCleanup(long space);

	public final static native void dSpaceSetSublevel(long space, int sublevel);

	public final static native int dSpaceGetSublevel(long space);

	public final static native void dSpaceSetManualCleanup(long space, int mode);

	public final static native int dSpaceGetManualCleanup(long space);

	public final static native void dSpaceAdd(long space, long GeomID);

	public final static native void dSpaceRemove(long space, long GeomID);

	public final static native int dSpaceQuery(long space, long GeomID);

	public final static native void dSpaceClean(long space);

	public final static native int dSpaceGetNumGeoms(long space);

	public final static native long dSpaceGetGeom(long space, int i);

	public final static native int dSpaceGetClass(long space);

	// ---------------------- TriMesh

	public final static native long dGeomTriMeshDataCreate();

	public final static native void dGeomTriMeshDataDestroy(long g);

	public final static native void dGeomTriMeshDataSet(long g, int data_id,
			Buffer in_data);

	public final static native Buffer dGeomTriMeshDataGet(long g, int data_id);

	public final static native void dGeomTriMeshSetLastTransform(long g,
			float[] last_trans);

	public final static native float[] dGeomTriMeshGetLastTransform(long g);

	public final static native void dGeomTriMeshDataBuildSingle(long g,
			float[] Vertices, int VertexStride, int VertexCount,
			int[] Indices, int IndexCount, int TriStride);

	public final static native void dGeomTriMeshDataBuildSingle1(long g,
			float[] Vertices, int VertexStride, int VertexCount,
			int[] Indices, int IndexCount, int TriStride, float[] Normals);

	public final static native void dGeomTriMeshDataBuildDouble(long g,
			double[] Vertices, int VertexStride, int VertexCount,
			int[] Indices, int IndexCount, int TriStride);

	public final static native void dGeomTriMeshDataBuildDouble1(long g,
			double[] Vertices, int VertexStride, int VertexCount,
			int[] Indices, int IndexCount, int TriStride, double[] Normals);

	public final static native void dGeomTriMeshDataBuildSimple(long g,
			float[] Vertices, int VertexCount, int[] Indices, int IndexCount);

	public final static native void dGeomTriMeshDataBuildSimple1(long g,
			float[] Vertices, int VertexCount, int[] Indices, int IndexCount,
			int[] Normals);

	public final static native void dGeomTriMeshDataPreprocess(long g);

	public final static native void dGeomTriMeshDataGetBuffer(long g,
			byte[] buf, int[] bufLen);

	public final static native void dGeomTriMeshDataSetBuffer(long g, byte[] buf);

/*
	public final static native void dGeomTriMeshSetCallback(long g, dTriCallback[] Callback);
	public final static native dTriCallback[] dGeomTriMeshGetCallback(long g);
	public final static native void dGeomTriMeshSetArrayCallback(long GeomID, dTriArrayCallback[] ArrayCallback);
	public final static native dTriArrayCallback[] dGeomTriMeshGetArrayCallback(long GeomID);
	public final static native void dGeomTriMeshSetRayCallback(long GeomID, dTriRayCallback[] Callback);
	public final static native dTriRayCallback[] dGeomTriMeshGetRayCallback(long GeomID);
	public final static native void dGeomTriMeshSetTriMergeCallback(long GeomID, dTriTriMergeCallback[] Callback);
	public final static native dTriTriMergeCallback[] dGeomTriMeshGetTriMergeCallback(long GeomID);
*/	
	public final static native long dCreateTriMesh(long space, long Data);

	public final static native void dGeomTriMeshSetData(long GeomID, long Data);

	public final static native long dGeomTriMeshGetData(long GeomID);

	public final static native void dGeomTriMeshEnableTC(long GeomID,
			int geomClass, int enable);

	public final static native int dGeomTriMeshIsTCEnabled(long GeomID,
			int geomClass);

	public final static native void dGeomTriMeshClearTCCache(long GeomID);

	public final static native long dGeomTriMeshGetTriMeshDataID(long GeomID);

	public final static native void dGeomTriMeshGetTriangle(long GeomID,
			int Index, float[] v0, float[] v1, float[] v2);

	public final static native void dGeomTriMeshGetPoint(long GeomID,
			int Index, float u, float v, float[] Out);

	public final static native int dGeomTriMeshGetTriangleCount(long GeomID);

	public final static native void dGeomTriMeshDataUpdate(long g);

	// ---------------------- config

	public final static native String dGetConfiguration();

	public final static native int dCheckConfiguration(String token);

	// public final static native void dSetErrorHandler (dMessageFunction []fn);
	// public final static native void dSetDebugHandler (dMessageFunction []fn);
	// public final static native void dSetMessageHandler (dMessageFunction
	// []fn);
	// public final static native dMessageFunction[] dGetErrorHandler();
	// public final static native dMessageFunction[] dGetDebugHandler();
	// public final static native dMessageFunction[] dGetMessageHandler();

	// public final static native void dError (int num, String msg, ...);
	// public final static native void dDebug (int num, String msg, ...);
	// public final static native void dMessage (int num, String msg, ...);

	// public final static native void dWorldExportDIF (long world, FILE []file,
	// String world_name);

	// ---------------------- mass

	public final static native int dMassCheck(long massm);

	public final static native void dMassSetZero(long mass);

	public final static native void dMassSetParameters(long mass,
			float themass, float cgx, float cgy, float cgz, float I11,
			float I22, float I33, float I12, float I13, float I23);

	public final static native void dMassSetSphere(long mass, float density,
			float radius);

	public final static native void dMassSetSphereTotal(long mass,
			float total_mass, float radius);

	public final static native void dMassSetCapsule(long mass, float density,
			int direction, float radius, float length);

	public final static native void dMassSetCapsuleTotal(long mass,
			float total_mass, int direction, float radius, float length);

	public final static native void dMassSetCylinder(long mass, float density,
			int direction, float radius, float length);

	public final static native void dMassSetCylinderTotal(long mass,
			float total_mass, int direction, float radius, float length);

	public final static native void dMassSetBox(long mass, float density,
			float lx, float ly, float lz);

	public final static native void dMassSetBoxTotal(long mass,
			float total_mass, float lx, float ly, float lz);

	public final static native void dMassSetTrimesh(long mass, float density,
			long GeomID);

	public final static native void dMassSetTrimeshTotal(long massm,
			float total_mass, long GeomID);

	public final static native void dMassAdjust(long mass, float newmass);

	public final static native void dMassTranslate(long mass, float x, float y,
			float z);

	public final static native void dMassRotate(long mass, float[] R);

	public final static native void dMassAdd(long a, long b);

	public final static native long dMassCreate();

	public final static native void dMassDestroy(long handle);
	
	// -------------------- world
	
	public final static native long dWorldCreate();

	public final static native void dWorldDestroy(long world);

	public final static native void dWorldSetGravity(long world, float x,
			float y, float z);

	public final static native void dWorldGetGravity(long world, float[] gravity);

	public final static native void dWorldSetERP(long world, float erp);

	public final static native float dWorldGetERP(long world);

	public final static native void dWorldSetCFM(long world, float cfm);

	public final static native float dWorldGetCFM(long world);

	public final static native int dWorldUseSharedWorkingMemory(long world,	long from_world);

	public final static native void dWorldCleanupWorkingMemory(long world);

	// public final static native int dWorldSetStepMemoryReservationPolicy(long world, dWorldStepReserveInfo []policyinfo/*=NULL*/);
	// public final static native int dWorldSetStepMemoryManager(long world, dWorldStepMemoryFunctionsInfo []memfuncs);
	public final static native int dWorldStep(long world, float stepsize);

	public final static native int dWorldQuickStep(long world, float stepsize);

	public final static native void dWorldImpulseToForce(long world,
			float stepsize, float ix, float iy, float iz, float[] force);

	public final static native void dWorldSetQuickStepNumIterations(long world,
			int num);

	public final static native int dWorldGetQuickStepNumIterations(long world);

	public final static native void dWorldSetQuickStepW(long world,
			float over_relaxation);

	public final static native float dWorldGetQuickStepW(long world);

	public final static native void dWorldSetContactMaxCorrectingVel(
			long world, float vel);

	public final static native float dWorldGetContactMaxCorrectingVel(long world);

	public final static native void dWorldSetContactSurfaceLayer(long world,
			float depth);

	public final static native float dWorldGetContactSurfaceLayer(long world);

	public final static native float dWorldGetAutoDisableLinearThreshold(
			long world);

	public final static native void dWorldSetAutoDisableLinearThreshold(
			long world, float linear_threshold);

	public final static native float dWorldGetAutoDisableAngularThreshold(
			long world);

	public final static native void dWorldSetAutoDisableAngularThreshold(
			long world, float angular_threshold);

	public final static native float dWorldGetAutoDisableLinearAverageThreshold(
			long world);

	public final static native void dWorldSetAutoDisableLinearAverageThreshold(
			long world, float linear_average_threshold);

	public final static native float dWorldGetAutoDisableAngularAverageThreshold(
			long world);

	public final static native void dWorldSetAutoDisableAngularAverageThreshold(
			long world, float angular_average_threshold);

	public final static native int dWorldGetAutoDisableAverageSamplesCount(
			long world);

	public final static native void dWorldSetAutoDisableAverageSamplesCount(
			long world, int average_samples_count);

	public final static native int dWorldGetAutoDisableSteps(long world);

	public final static native void dWorldSetAutoDisableSteps(long world,
			int steps);

	public final static native float dWorldGetAutoDisableTime(long world);

	public final static native void dWorldSetAutoDisableTime(long world,
			float time);

	public final static native int dWorldGetAutoDisableFlag(long world);

	public final static native void dWorldSetAutoDisableFlag(long world,
			int do_auto_disable);

	public final static native float dWorldGetLinearDampingThreshold(long world);

	public final static native void dWorldSetLinearDampingThreshold(long world,
			float threshold);

	public final static native float dWorldGetAngularDampingThreshold(long world);

	public final static native void dWorldSetAngularDampingThreshold(
			long world, float threshold);

	public final static native float dWorldGetLinearDamping(long world);

	public final static native void dWorldSetLinearDamping(long world,
			float scale);

	public final static native float dWorldGetAngularDamping(long world);

	public final static native void dWorldSetAngularDamping(long world,
			float scale);

	public final static native void dWorldSetDamping(long world,
			float linear_scale, float angular_scale);

	public final static native float dWorldGetMaxAngularSpeed(long world);

	public final static native void dWorldSetMaxAngularSpeed(long world,
			float max_speed);

	// ---------------------- body

	public final static native float dBodyGetAutoDisableLinearThreshold(
			long body);

	public final static native void dBodySetAutoDisableLinearThreshold(
			long body, float linear_average_threshold);

	public final static native float dBodyGetAutoDisableAngularThreshold(
			long body);

	public final static native void dBodySetAutoDisableAngularThreshold(
			long body, float angular_average_threshold);

	public final static native int dBodyGetAutoDisableAverageSamplesCount(
			long body);

	public final static native void dBodySetAutoDisableAverageSamplesCount(
			long body, int average_samples_count);

	public final static native int dBodyGetAutoDisableSteps(long body);

	public final static native void dBodySetAutoDisableSteps(long body,
			int steps);

	public final static native float dBodyGetAutoDisableTime(long body);

	public final static native void dBodySetAutoDisableTime(long body,
			float time);

	public final static native int dBodyGetAutoDisableFlag(long body);

	public final static native void dBodySetAutoDisableFlag(long body,
			int do_auto_disable);

	public final static native void dBodySetAutoDisableDefaults(long body);

	public final static native long dBodyGetWorld(long body);

	public final static native long dBodyCreate(long world);

	public final static native void dBodyDestroy(long body);

	public final static native void dBodySetData(long body, Object data);

	public final static native Object dBodyGetData(long body);

	public final static native void dBodySetPosition(long body, float x,
			float y, float z);

	public final static native void dBodySetRotation(long body, float[] R);

	public final static native void dBodySetQuaternion(long body, float[] q);

	public final static native void dBodySetLinearVel(long body, float x,
			float y, float z);

	public final static native void dBodySetAngularVel(long body, float x,
			float y, float z);

	public final static native float[] dBodyGetPosition(long body);

	public final static native void dBodyCopyPosition(long body, float[] pos);

	public final static native float[] dBodyGetRotation(long body);

	public final static native void dBodyCopyRotation(long body, float[] R);

	public final static native float[] dBodyGetQuaternion(long body);

	public final static native void dBodyCopyQuaternion(long body, float[] quat);

	public final static native float[] dBodyGetLinearVel(long body);

	public final static native float[] dBodyGetAngularVel(long body);

	public final static native void dBodySetMass(long body, long mass);

	public final static native void dBodyGetMass(long body, long mass);

	public final static native void dBodyAddForce(long body, float fx,
			float fy, float fz);

	public final static native void dBodyAddTorque(long body, float fx,
			float fy, float fz);

	public final static native void dBodyAddRelForce(long body, float fx,
			float fy, float fz);

	public final static native void dBodyAddRelTorque(long body, float fx,
			float fy, float fz);

	public final static native void dBodyAddForceAtPos(long body, float fx,
			float fy, float fz, float px, float py, float pz);

	public final static native void dBodyAddForceAtRelPos(long body, float fx,
			float fy, float fz, float px, float py, float pz);

	public final static native void dBodyAddRelForceAtPos(long body, float fx,
			float fy, float fz, float px, float py, float pz);

	public final static native void dBodyAddRelForceAtRelPos(long body,
			float fx, float fy, float fz, float px, float py, float pz);

	public final static native float[] dBodyGetForce(long body);

	public final static native float[] dBodyGetTorque(long body);

	public final static native void dBodySetForce(long b, float x, float y,
			float z);

	public final static native void dBodySetTorque(long b, float x, float y,
			float z);

	public final static native void dBodyGetRelPointPos(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodyGetRelPointVel(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodyGetPointVel(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodyGetPosRelPoint(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodyVectorToWorld(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodyVectorFromWorld(long body, float px,
			float py, float pz, float[] result);

	public final static native void dBodySetFiniteRotationMode(long body,
			int mode);

	public final static native void dBodySetFiniteRotationAxis(long body,
			float x, float y, float z);

	public final static native int dBodyGetFiniteRotationMode(long body);

	public final static native void dBodyGetFiniteRotationAxis(long body,
			float[] result);

	public final static native int dBodyGetNumJoints(long b);

	public final static native long dBodyGetJoint(long body, int index);

	public final static native void dBodySetDynamic(long body);

	public final static native void dBodySetKinematic(long body);

	public final static native int dBodyIsKinematic(long body);

	public final static native void dBodyEnable(long body);

	public final static native void dBodyDisable(long body);

	public final static native int dBodyIsEnabled(long body);

	public final static native void dBodySetGravityMode(long b, int mode);

	public final static native int dBodyGetGravityMode(long b);

	public final static native long dBodyGetFirstGeom(long b);

	public final static native long dBodyGetNextGeom(long GeomID);

	public final static native void dBodySetDampingDefaults(long b);

	public final static native float dBodyGetLinearDamping(long b);

	public final static native void dBodySetLinearDamping(long b, float scale);

	public final static native float dBodyGetAngularDamping(long b);

	public final static native void dBodySetAngularDamping(long b, float scale);

	public final static native void dBodySetDamping(long b, float linear_scale,
			float angular_scale);

	public final static native float dBodyGetLinearDampingThreshold(long b);

	public final static native void dBodySetLinearDampingThreshold(long b,
			float threshold);

	public final static native float dBodyGetAngularDampingThreshold(long b);

	public final static native void dBodySetAngularDampingThreshold(long b,
			float threshold);

	public final static native float dBodyGetMaxAngularSpeed(long b);

	public final static native void dBodySetMaxAngularSpeed(long b,
			float max_speed);

	public final static native int dBodyGetGyroscopicMode(long b);

	public final static native void dBodySetGyroscopicMode(long b, int enabled);

	// ---------------------- joints

	public final static native long dJointCreateBall(long world,
			long jointGroupID);

	public final static native long dJointCreateHinge(long world,
			long jointGroupID);

	public final static native long dJointCreateSlider(long world,
			long jointGroupID);

	public final static native long dJointCreateContact(long world,
			long jointGroupID, long contact);

	public final static native long dJointCreateHinge2(long world,
			long jointGroupID);

	public final static native long dJointCreateUniversal(long world,
			long jointGroupID);

	public final static native long dJointCreatePR(long world, long jointGroupID);

	public final static native long dJointCreatePU(long world, long jointGroupID);

	public final static native long dJointCreatePiston(long world,
			long jointGroupID);

	public final static native long dJointCreateFixed(long world,
			long jointGroupID);

	public final static native long dJointCreateNull(long world,
			long jointGroupID);

	public final static native long dJointCreateAMotor(long world,
			long jointGroupID);

	public final static native long dJointCreateLMotor(long world,
			long jointGroupID);

	public final static native long dJointCreatePlane2D(long world,
			long jointGroupID);

	public final static native void dJointDestroy(long joint);

	public final static native long dJointGroupCreate(int max_size);

	public final static native void dJointGroupDestroy(long jointGroupID);

	public final static native void dJointGroupEmpty(long jointGroupID);

	public final static native int dJointGetNumBodies(long joint);

	public final static native void dJointAttach(long joint, long body1,
			long body2);

	public final static native void dJointEnable(long joint);

	public final static native void dJointDisable(long joint);

	public final static native int dJointIsEnabled(long joint);

	public final static native void dJointSetData(long joint, Object data);

	public final static native Object dJointGetData(long joint);

	public final static native int dJointGetType(long joint);

	public final static native long dJointGetBody(long joint, int index);

	public final static native void dJointSetFeedback(long joint,
			long jointFeedback);

	public final static native long dJointGetFeedback(long joint);

	public final static native void dJointSetBallAnchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetBallAnchor2(long joint, float x,
			float y, float z);

	public final static native void dJointSetBallParam(long joint,
			int parameter, float value);

	public final static native void dJointSetHingeAnchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetHingeAnchorDelta(long joint,
			float x, float y, float z, float ax, float ay, float az);

	public final static native void dJointSetHingeAxis(long joint, float x,
			float y, float z);

	public final static native void dJointSetHingeAxisOffset(long joint,
			float x, float y, float z, float angle);

	public final static native void dJointSetHingeParam(long joint,
			int parameter, float value);

	public final static native void dJointAddHingeTorque(long joint,
			float torque);

	public final static native void dJointSetSliderAxis(long joint, float x,
			float y, float z);

	public final static native void dJointSetSliderAxisDelta(long joint,
			float x, float y, float z, float ax, float ay, float az);

	public final static native void dJointSetSliderParam(long joint,
			int parameter, float value);

	public final static native void dJointAddSliderForce(long joint, float force);

	public final static native void dJointSetHinge2Anchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetHinge2Axis1(long joint, float x,
			float y, float z);

	public final static native void dJointSetHinge2Axis2(long joint, float x,
			float y, float z);

	public final static native void dJointSetHinge2Param(long joint,
			int parameter, float value);

	public final static native void dJointAddHinge2Torques(long joint,
			float torque1, float torque2);

	public final static native void dJointSetUniversalAnchor(long joint,
			float x, float y, float z);

	public final static native void dJointSetUniversalAxis1(long joint,
			float x, float y, float z);

	public final static native void dJointSetUniversalAxis1Offset(long joint,
			float x, float y, float z, float offset1, float offset2);

	public final static native void dJointSetUniversalAxis2(long joint,
			float x, float y, float z);

	public final static native void dJointSetUniversalAxis2Offset(long joint,
			float x, float y, float z, float offset1, float offset2);

	public final static native void dJointSetUniversalParam(long joint,
			int parameter, float value);

	public final static native void dJointAddUniversalTorques(long joint,
			float torque1, float torque2);

	public final static native void dJointSetPRAnchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetPRAxis1(long joint, float x,
			float y, float z);

	public final static native void dJointSetPRAxis2(long joint, float x,
			float y, float z);

	public final static native void dJointSetPRParam(long joint, int parameter,
			float value);

	public final static native void dJointAddPRTorque(long joint, float torque);

	public final static native void dJointSetPUAnchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetPUAnchorOffset(long joint,
			float x, float y, float z, float dx, float dy, float dz);

	public final static native void dJointSetPUAxis1(long joint, float x,
			float y, float z);

	public final static native void dJointSetPUAxis2(long joint, float x,
			float y, float z);

	public final static native void dJointSetPUAxis3(long joint, float x,
			float y, float z);

	public final static native void dJointSetPUAxisP(long joint, float x,
			float y, float z);

	public final static native void dJointSetPUParam(long joint, int parameter,
			float value);

	public final static native void dJointSetPistonAnchor(long joint, float x,
			float y, float z);

	public final static native void dJointSetPistonAnchorOffset(long joint,
			float x, float y, float z, float dx, float dy, float dz);

	public final static native void dJointSetPistonAxis(long joint, float x,
			float y, float z);

	public final static native void dJointSetPistonParam(long joint,
			int parameter, float value);

	public final static native void dJointAddPistonForce(long joint, float force);

	public final static native void dJointSetFixed(long joint);

	public final static native void dJointSetFixedParam(long joint,
			int parameter, float value);

	public final static native void dJointSetAMotorNumAxes(long joint, int num);

	public final static native void dJointSetAMotorAxis(long joint, int anum,
			int rel, float x, float y, float z);

	public final static native void dJointSetAMotorAngle(long joint, int anum,
			float angle);

	public final static native void dJointSetAMotorParam(long joint,
			int parameter, float value);

	public final static native void dJointSetAMotorMode(long joint, int mode);

	public final static native void dJointAddAMotorTorques(long joint,
			float torque1, float torque2, float torque3);

	public final static native void dJointSetLMotorNumAxes(long joint, int num);

	public final static native void dJointSetLMotorAxis(long joint, int anum,
			int rel, float x, float y, float z);

	public final static native void dJointSetLMotorParam(long joint,
			int parameter, float value);

	public final static native void dJointSetPlane2DXParam(long joint,
			int parameter, float value);

	public final static native void dJointSetPlane2DYParam(long joint,
			int parameter, float value);

	public final static native void dJointSetPlane2DAngleParam(long joint,
			int parameter, float value);

	public final static native void dJointGetBallAnchor(long joint,
			float[] result);

	public final static native void dJointGetBallAnchor2(long joint,
			float[] result);

	public final static native float dJointGetBallParam(long joint,
			int parameter);

	public final static native void dJointGetHingeAnchor(long joint,
			float[] result);

	public final static native void dJointGetHingeAnchor2(long joint,
			float[] result);

	public final static native void dJointGetHingeAxis(long joint,
			float[] result);

	public final static native float dJointGetHingeParam(long joint,
			int parameter);

	public final static native float dJointGetHingeAngle(long joint);

	public final static native float dJointGetHingeAngleRate(long joint);

	public final static native float dJointGetSliderPosition(long joint);

	public final static native float dJointGetSliderPositionRate(long joint);

	public final static native void dJointGetSliderAxis(long joint,
			float[] result);

	public final static native float dJointGetSliderParam(long joint,
			int parameter);

	public final static native void dJointGetHinge2Anchor(long joint,
			float[] result);

	public final static native void dJointGetHinge2Anchor2(long joint,
			float[] result);

	public final static native void dJointGetHinge2Axis1(long joint,
			float[] result);

	public final static native void dJointGetHinge2Axis2(long joint,
			float[] result);

	public final static native float dJointGetHinge2Param(long joint,
			int parameter);

	public final static native float dJointGetHinge2Angle1(long joint);

	public final static native float dJointGetHinge2Angle1Rate(long joint);

	public final static native float dJointGetHinge2Angle2Rate(long joint);

	public final static native void dJointGetUniversalAnchor(long joint,
			float[] result);

	public final static native void dJointGetUniversalAnchor2(long joint,
			float[] result);

	public final static native void dJointGetUniversalAxis1(long joint,
			float[] result);

	public final static native void dJointGetUniversalAxis2(long joint,
			float[] result);

	public final static native float dJointGetUniversalParam(long joint,
			int parameter);

	public final static native void dJointGetUniversalAngles(long joint,
			float[] angle1, float[] angle2);

	public final static native float dJointGetUniversalAngle1(long joint);

	public final static native float dJointGetUniversalAngle2(long joint);

	public final static native float dJointGetUniversalAngle1Rate(long joint);

	public final static native float dJointGetUniversalAngle2Rate(long joint);

	public final static native void dJointGetPRAnchor(long joint, float[] result);

	public final static native float dJointGetPRPosition(long joint);

	public final static native float dJointGetPRPositionRate(long joint);

	public final static native float dJointGetPRAngle(long joint);

	public final static native float dJointGetPRAngleRate(long joint);

	public final static native void dJointGetPRAxis1(long joint, float[] result);

	public final static native void dJointGetPRAxis2(long joint, float[] result);

	public final static native float dJointGetPRParam(long joint, int parameter);

	public final static native void dJointGetPUAnchor(long joint, float[] result);

	public final static native float dJointGetPUPosition(long joint);

	public final static native float dJointGetPUPositionRate(long joint);

	public final static native void dJointGetPUAxis1(long joint, float[] result);

	public final static native void dJointGetPUAxis2(long joint, float[] result);

	public final static native void dJointGetPUAxis3(long joint, float[] result);

	public final static native void dJointGetPUAxisP(long joint, float[] result);

	public final static native void dJointGetPUAngles(long joint,
			float[] angle1, float[] angle2);

	public final static native float dJointGetPUAngle1(long joint);

	public final static native float dJointGetPUAngle1Rate(long joint);

	public final static native float dJointGetPUAngle2(long joint);

	public final static native float dJointGetPUAngle2Rate(long joint);

	public final static native float dJointGetPUParam(long joint, int parameter);

	public final static native float dJointGetPistonPosition(long joint);

	public final static native float dJointGetPistonPositionRate(long joint);

	public final static native float dJointGetPistonAngle(long joint);

	public final static native float dJointGetPistonAngleRate(long joint);

	public final static native void dJointGetPistonAnchor(long joint,
			float[] result);

	public final static native void dJointGetPistonAnchor2(long joint,
			float[] result);

	public final static native void dJointGetPistonAxis(long joint,
			float[] result);

	public final static native float dJointGetPistonParam(long joint,
			int parameter);

	public final static native int dJointGetAMotorNumAxes(long joint);

	public final static native void dJointGetAMotorAxis(long joint, int anum,
			float[] result);

	public final static native int dJointGetAMotorAxisRel(long joint, int anum);

	public final static native float dJointGetAMotorAngle(long joint, int anum);

	public final static native float dJointGetAMotorAngleRate(long joint,
			int anum);

	public final static native float dJointGetAMotorParam(long joint,
			int parameter);

	public final static native int dJointGetAMotorMode(long joint);

	public final static native int dJointGetLMotorNumAxes(long joint);

	public final static native void dJointGetLMotorAxis(long joint, int anum,
			float[] result);

	public final static native float dJointGetLMotorParam(long joint,
			int parameter);

	public final static native float dJointGetFixedParam(long joint,
			int parameter);

	public final static native long dConnectingJoint(long body1, long body2);

	public final static native int dConnectingJointList(long body1, long body2,
			long[] joint);

	public final static native int dAreConnected(long body1, long body2);

	public final static native int dAreConnectedExcluding(long body1,
			long body2, int joint_type);

	// ---------------------- init

	public final static native void dInitODE();

	public final static native int dInitODE2(int uiInitFlags/* =0 */);

	public final static native int dAllocateODEDataForThread(int uiAllocateFlags);

	public final static native void dCleanupODEAllDataForThread();

	public final static native void dCloseODE();

	public final static native void longReset(long[] stopwatches);

	public final static native void longStart(long[] stopwatches);

	public final static native void longStop(long[] stopwatches);

	public final static native double longTime(long[] stopwatches);

	public final static native void dTimerStart(String description);

	public final static native void dTimerNow(String description);

	public final static native void dTimerEnd();

	public final static native double dTimerTicksPerSecond();

	public final static native double dTimerResolution();

	// custom funcs
	public static native void setFeedback(long feedback,float[] f1,float[] f2,float[] t1,float[] t2);
	public static native float[] getFeedback(long feedback);
	
	protected static native void setCallbackNative(long body);
	protected static native long[] getCallbacksNative();
	protected static native void collideNative(long space);
	
	protected static native long CreateContact();
	protected static native void DestroyContact(long id);
	
	protected static native void contactSetFdir(long id,float[] arr);
	protected static native float[] contactGetFdir(long id);
	
	protected static native long contactgeomGetContactGeom(long id);
	protected static native void contactgeomSetDepth(long id,float depth);
	protected static native void contactgeomSetG1(long id,long g1);
	protected static native void contactgeomSetG2(long id,long g2);
	protected static native void contactgeomSetNormal(long id,float[] normal);
	protected static native void contactgeomSetPos(long id,float[] pos);

	protected static native float contactgeomGetDepth(long id);
	protected static native long contactgeomGetG1(long id);
	protected static native long contactgeomGetG2(long id);
	protected static native float[] contactgeomGetNormal(long id);
	protected static native float[] contactgeomGetPos(long id);
	
	protected static native long contactGetSurface(long id);
	
	protected static native void SurfaceParametersSetBounce(long id,float bounce);
	protected static native void SurfaceParametersSetBounceVel(long id,float bounce);
	protected static native void SurfaceParametersSetMode(long id,int mode);
	protected static native void SurfaceParametersSetMotion1(long id,float m);
	protected static native void SurfaceParametersSetMotion2(long id,float m);
	protected static native void SurfaceParametersSetMotionN(long id,float m);
	protected static native void SurfaceParametersSetMu(long id,float m);
	protected static native void SurfaceParametersSetMu2(long id,float m);
	protected static native void SurfaceParametersSetSlip1(long id,float m);
	protected static native void SurfaceParametersSetSlip2(long id,float m);
	protected static native void SurfaceParametersSetSoftCFM(long id,float m);
	protected static native void SurfaceParametersSetSoftERP(long id,float m);
	protected static native float SurfaceParametersGetBounce(long id);
	protected static native float SurfaceParametersGetBounceVel(long id);
	protected static native float SurfaceParametersGetMode(long id);
	protected static native float SurfaceParametersGetMotion1(long id);
	protected static native float SurfaceParametersGetMotion2(long id);
	protected static native float SurfaceParametersGetMotionN(long id);
	protected static native float SurfaceParametersGetMu(long id);
	protected static native float SurfaceParametersGetMu2(long id);
	protected static native float SurfaceParametersGetSlip1(long id);
	protected static native float SurfaceParametersGetSlip2(long id);
	protected static native float SurfaceParametersGetSoftCFM(long id);
	protected static native float SurfaceParametersGetSoftERP(long id);

	// this is a function , as there's no guarantee Float.POSITIVE_INFINITY is the same as ode's dInfinity
	public static native float dInfinity();

	private final static native int dCollide(long o1, long o2, int flags, long[] contacts);
	private final static native int dCollide(long o1, long o2, long contact);

	public static int dCollide(Geom g1,Geom g2,Contact contact){
		return dCollide(g1.handle,g2.handle,contact.handle);
	}
	public static int dCollide(Geom g1,Geom g2,int flags,Contact[] contact){
		long[] contacts=new long[contact.length];
		for (int i=0;i<contact.length;i++){
			contacts[i]=contact[i].handle;
		}
		return dCollide(g1.handle,g2.handle,flags,contacts);
	}
	
	// ---------------------- funcs

	public final static native int dFactorCholesky(float[] A, int n);
	public final static native void dSolveCholesky(float[] L, float[] b, int n);
	public final static native int dInvertPDMatrix(float[] A, float[] Ainv, int n);
	public final static native int dIsPositiveDefinite(float[] A, int n);
	public final static native void dFactorLDLT(float[] A, float[] d, int n, int nskip);
	public final static native void dSolveL1(float[] L, float[] b, int n, int nskip);
	public final static native void dSolveL1T(float[] L, float[] b, int n, int nskip);
	public final static native void dVectorScale(float[] a, float[] d, int n);
	public final static native void dSolveLDLT(float[] L, float[] d, float[] b, int n, int nskip);
	public final static native void dLDLTAddTL(float[] L, float[] d, float[] a, int n, int nskip);
	public final static native void dLDLTRemove(float[][] A, int[] p, float[] L, float[] d, int n1, int n2, int r, int nskip);


}
